(:
   An example of a display stylesheet

   Parameters of the script :
      name of the display file
      number of the item
      number of the info element dans l'item
      number of the column being formatted

   Result is a sequence :
      type of the result (a string)
      main value of the result
      additional result information.

   Ex :
      ("img" , "toto.png") for a picture
      ("txt" , "a chunk of text", "red") for a colored text, etc.
:)
module namespace dss = "http://kumquat.emse.fr/stylesheet" ;

import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;

(:
    Main formating procedure
:)
declare function dss:fmtinfo($doc as node(), $item as xs:integer,
                             $info as xs:integer, $col as xs:integer)
   as xs:string
{
   let $e = $doc/display/item[$item],   (: l'item courant :)
       $i = $e/info[$info],      (: l'info courante :)
       $n = $i/@name,            (: le nom associé à l'info courante :)
       $t =                      (: le type associé à l'info courante :)
            if ($i/elem()) xsd:name($i/elem())
            else ''
   return
   (: date and time is always edited as the first occurence of date :)
   if ($t == 'time')
       ("txt:", jj:dateFromDREW($i/time/date[1]))
   else
   (: the type of the tool in 2 first columns is edited as an icon :)
   if ($n == 'type' and $col < 3)
       ("img", concat("icon-",$i/node(), ".png"))
   else
   (: an image :)
   if ($t == 'img' or $t == 'icon')
       ("img", $i/img/node() )
   else
   (: a text :)
   if ($t == 'text')
       ("txt", $i/text/node())
   else
   (: a plain text :)
   if ($t == '')
       ("txt", $i/node())
   else
       ("txt", "")
}

